package com.artifact.mit.mypoint.adapter;

import static com.artifact.mit.mypoint.service.util.FormatHelper.appendImageUrl;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.artifact.mit.mypoint.R;
import com.artifact.mit.mypoint.service.async.ImageLoader;
import com.artifact.mit.mypoint.service.model.SetImage;
import com.artifact.mit.mypoint.service.model.api.Promo;

public class PromoAdapter extends ArrayAdapter<Promo.Promos> {

	public PromoAdapter(Context context) {
		super(context, 0);
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(getContext()).inflate(R.layout.promo, null);
		}
		
		TextView promoTitle = (TextView) convertView.findViewById(R.id.promoText1);
		TextView promoDesc = (TextView) convertView.findViewById(R.id.promoText2);
		ImageView promoImage = (ImageView) convertView.findViewById(R.id.promoImage1);
				
		promoTitle.setText(getItem(position).getName());
		promoDesc.setText(getItem(position).getDesc());
//		promoImage.setImageResource(getItem(position).image);
		new ImageLoader().execute(new SetImage(promoImage, appendImageUrl(getItem(position).getUrlImage()), false));
		
		return convertView;
	}
}
